package rank1400;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Queue;

/**
 * 1700. 无法吃午餐的学生数量
 */
public class No1700 {
    public int countStudents(int[] students, int[] sandwiches) {
        Queue<Integer> queue = new LinkedList<>();
        Deque<Integer> stack = new LinkedList<>();
        for (int student : students) {
            queue.offer(student);
        }
        for (int sandwich : sandwiches) {
            stack.offer(sandwich);
        }
        boolean flag = true;
        while (flag) {
            flag = false;
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                if (Objects.equals(queue.peek(), stack.peek())) {
                    queue.poll();
                    stack.pop();
                    flag = true;
                }else {
                    queue.offer(queue.poll());
                }
            }
        }
        return queue.size();
    }
}
